# Base层提供抽象的方法行为
# 其实是selenium的2次封装
#导入所有我们需要的包名称
from selenium.webdriver.support.select import Select

from teacher.ecshop.utils.Logger import Logger

logger = Logger('Base').getlog()

#定义Base类，在Base类中加入我们需要用到的方法
class Base():
    def __init__(self, driver):
        self.driver = driver

    def open(self, url):
        self.driver.get(url)
        logger.info(f'打开了{url}网址')
        self.driver.maximize_window()
        logger.info('浏览器窗口最大化')

    def find_element(self, *locator):
        return self.driver.find_element(*locator)

    def input(self, locator, text):
        self.find_element(*locator).send_keys(text)
        logger.info(f'{locator}在中输入{text}')

    def click(self, locator):
        self.find_element(*locator).click()
        logger.info(f'点击{locator}元素')

    def into_frame(self, frame_name):
        self.driver.switch_to.frame(frame_name)
        logger.info('进入内帧')

    def out_frame(self):
        self.driver.switch_to.default_content()
        logger.info('退出内帧')

    def select_by_text(self, locator, text):
        Select(self.find_element(*locator)).select_by_visible_text(text)
        logger.info(f'在下拉框{locator}中选择{text}')

    def get_text(self, locator):
        return self.find_element(*locator).text
        logger.info(f'获取{locator}中的{text}内容')

    # def get_text(self, locator):
    #     return self.find_element(*locator).text
